#include "ByteArray.h"
#include <boost/variant/get.hpp>

namespace lhcutils
{

ByteArray::ByteArray(QByteArray bytes) : m_underlying(bytes) //m_bytes(bytes)
{
	;
}

ByteArray::ByteArray(Utf16Array utf16) : m_underlying(utf16)
{
	;
}

ByteArray::ByteArray(Utf32Array utf32) : m_underlying(utf32)
{
	;
}

const boost::uint8_t* ByteArray::Ptr() const
{
	const QByteArray* utf8OrAsciiBytes = boost::get<QByteArray>(&m_underlying);
	if(utf8OrAsciiBytes != NULL)
	{
		return reinterpret_cast<const boost::uint8_t*>(utf8OrAsciiBytes->constData());
	}

	const Utf16Array* utf16Bytes = boost::get<Utf16Array>(&m_underlying);
	if(utf16Bytes != NULL)
	{
		return utf16Bytes->BytePtr();
	}
	else
	{
		const Utf32Array* utf32Bytes = boost::get<Utf32Array>(&m_underlying);
		return utf32Bytes->BytePtr();
	}
}

std::size_t ByteArray::Count() const
{
	const QByteArray* utf8OrAsciiBytes = boost::get<QByteArray>(&m_underlying);
	if(utf8OrAsciiBytes != NULL)
	{
		return utf8OrAsciiBytes->size();
	}

	const Utf16Array* utf16Bytes = boost::get<Utf16Array>(&m_underlying);
	if(utf16Bytes != NULL)
	{
		return utf16Bytes->ByteCount();
	}
	else
	{
		const Utf32Array* utf32Bytes = boost::get<Utf32Array>(&m_underlying);
		return utf32Bytes->ByteCount();
	}
}

}

/*
 Copyright 2011 Greg Najda

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
